package com.lzy.product.service.impl;

import com.lzy.framework.core.utils.DozerUtils;
import com.lzy.product.common.util.UserUtil;
import com.lzy.product.dao.ConditionMapperExt;
import com.lzy.product.dtos.ConditionDto;
import com.lzy.product.entity.Condition;
import com.lzy.product.service.ConditionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WIN7 on 2017/12/12.
 */
@Service
public class ConditionServiceImpl implements ConditionService {

    @Autowired
    ConditionMapperExt conditionMapperExt;

    @Override
    public Long insert(ConditionDto dto) {
        Condition condition = DozerUtils.map(dto, Condition.class);
        return conditionMapperExt.insertSelective(condition) > 0 ? condition.getId() : null;
    }

    @Override
    public Boolean update(ConditionDto dto) {
        return conditionMapperExt.updateByPrimaryKeySelective(DozerUtils.map(dto, Condition.class)) > 0;
    }

    @Override
    public Boolean delete(Long id) {
        return conditionMapperExt.deleteByPrimaryKey(id) > 0;
    }

    @Override
    public Boolean remove(Long id) {
        return conditionMapperExt.remove(id, UserUtil.getCurrentUser().getId()) > 0;
    }

    @Override
    public ConditionDto findById(Long id) {
        return DozerUtils.map(conditionMapperExt.selectByPrimaryKey(id), ConditionDto.class);
    }

    @Override
    public List<ConditionDto> query(ConditionDto dto) {
        return conditionMapperExt.selectList(dto);
    }
}
